// 这个是商品模块

//导入数据库模块
const db = require('../db/db')

const Shop = {
    async FierShop(pid){
        let sqlStr = 'SELECT b.* from log as a,shopdata as b WHERE a.id = b.pid AND a.id = ?'
        let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,pid,(err,res)=>{
                if(err) reject(err)

                resolve(res)
            })
        })
        return data
    },

    // 商品搜索模块(模糊查询)
    async Search(id,value){
        // console.log(id,value)
        let sqlStr = "SELECT b.* from log as a,shopdata as b WHERE a.id = b.pid AND a.id = ? AND sname REGEXP ? "
        let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,[id,value],(err,res)=>{
                if(err) reject(err)
                resolve(res)
            })
        })
        return data
    },

    // 商品详细信息查询
    async DetailShop(sid){
        let sqlStr = 'SELECT * FROM shopdata WHERE sid = ?'
        let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,sid,(err,res)=>{
                if(err) reject(err)
                resolve(res)
            })
        })
        return data
    },


    // 获取商品的尺码列表
    async SizeList(){
        let sqlStr = 'SELECT * FROM size'
        let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,(err,res)=>{
                if(err) reject(err)
                resolve(res)
            })
        })
        return data
    },
}


module.exports = Shop